package com.shanghaionstar.carmanage.presenter;

import com.onstar.cn.framework.mvp.base.IMVPScheduler;
import com.onstar.cn.framework.mvp.base.IMVPView;
import com.onstar.cn.framework.mvp.base.core.BaseActivity;
import com.onstar.cn.framework.mvp.base.core.BasePresenter;
import com.onstar.cn.mag.enumtype.RemoteCommandsType;
import com.onstar.cn.vehicle.result.PollingResult;
import com.shanghaionstar.carmanage.iview.ICarChargingView;
import com.shanghaionstar.remote.model.RemoteModel;
import com.shanghaionstar.remote.service.RemoteService;

import rx.functions.Action1;

/**
 * Created by 6335yz on 2016/7/24.
 */
public class CarChargeModePresenter extends BasePresenter {

    private static final float START_DEGREE = 0f;
    private static final float END_DEGREE = 180f;
    private ICarChargingView carChargingView;
    private BaseActivity baseActivity;
    private RemoteService remoteService;

    public CarChargeModePresenter(IMVPScheduler mvpScheduler, BaseActivity baseActivity) {
        super(mvpScheduler);
        this.baseActivity = baseActivity;
        remoteService = new RemoteService(baseActivity);
        getChargeMode();
    }

    @Override
    public void setView(IMVPView view) {
        super.setView(view);
        carChargingView = (ICarChargingView) view;
    }

    public void getChargeMode() {
        RemoteModel.Builder builder = new RemoteModel.Builder();
        builder.setRemoteCommandsType(RemoteCommandsType.COMMAND_GETCHARGINGPROFILE);
        subscription = remoteService.commandByType(builder.create())
                .subscribeOn(mvpScheduler.backgroundThread())
                .observeOn(mvpScheduler.mainThread())
                .subscribe(new Action1<String>() {
                    @Override
                    public void call(String s) {
                        if (carChargingView != null) {
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        //里面抛出的Error信息
                        if (carChargingView != null) {
                        }
                    }
                });
    }

    public void saveChargeMode() {
        /**
         * need to set by chargingProfileEntity
         */
        String body = "";
        RemoteModel.Builder builder = new RemoteModel.Builder();
        builder.setRemoteCommandsType(RemoteCommandsType.COMMAND_SETCHARGINGPROFILE).setBody(body);
        remoteService.commandByType(builder.create())
                .subscribeOn(mvpScheduler.backgroundThread())
                .observeOn(mvpScheduler.mainThread())
                .subscribe(new Action1<String>() {
                    @Override
                    public void call(String s) {
                        if (carChargingView != null) {
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        //里面抛出的Error信息
                        if (carChargingView != null) {
                        }
                    }
                });
    }

    /**
     * polling 回调
     * @param result
     */
    public void registPollCallBack(PollingResult result) {

    }
}
